# -*- coding: utf-8 -*-

# $Id: views.py 2 2012-09-01 15:54:17Z alexis.roda.villalonga@gmail.com $


from django.views.generic import ListView

import django_tables2 as tables


class DjangoTableListView(ListView):
    """Base class for list views based on django-tables2.

    Subclasses must initialize the class attribute 'table' with a
    'djanto_tables2.Table' subclass.

    Instances of this class add 'table' to the context data.
    """
    table = None

    def get_context_data(self, **kwargs):
        context = super(DjangoTableListView, self).get_context_data(**kwargs)
        table = self.table(context["object_list"])
        tables.RequestConfig(self.request).configure(table)
        context["table"] = table
        return context
